package view;

import com.trolltech.qt.gui.QCloseEvent;
import com.trolltech.qt.gui.QComboBox;
import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QPushButton;

public class EditorDialog extends QDialog {

    private final QLabel label;
    private final QComboBox boxNum;
    private final QPushButton okButton;
	private final int object;

	public EditorDialog(final MainWindow mainWindow,final int object) {		
		super(mainWindow);      
        
        final QHBoxLayout mainLayout = new QHBoxLayout();
        okButton = new QPushButton("Ok");
        label = new QLabel("Number of Car per Step:");
        
        
        boxNum = new QComboBox();
        boxNum.addItem("0");
        boxNum.addItem("1");
        boxNum.addItem("2");
        boxNum.addItem("3");
        boxNum.addItem("4");
        boxNum.addItem("5");
        boxNum.addItem("6");
        boxNum.addItem("7");
        boxNum.addItem("8");
        boxNum.addItem("9");

        
        this.object = object;
		String obj="Car per Step";
		
		switch (object) {
		case 0:
			setModal(true);
			
//	        lineEdit = new QLineEdit();
	        label.setBuddy(boxNum);


	        okButton.setDefault(true);
	        

	        mainLayout.addWidget(label);
	        mainLayout.addWidget(boxNum);
	        mainLayout.addWidget(okButton);

	        setLayout(mainLayout);
			
			
			okButton.clicked.connect(this,"buttonClicked()");
			okButton.clicked.connect(this,"close()");
			break;
			
			
			
			
		case 1:
			
			
			label.setText("Add cars on Map:");

	        okButton.setText("Save");
	        okButton.setDefault(true);
	       
	        mainLayout.addWidget(label);
	        mainLayout.addWidget(okButton);
	        setLayout(mainLayout);
	        
	        
	        ((MainWindow) parent()).setAddingCars(true);
	        
			
			okButton.clicked.connect(this,"buttonClicked()");
			okButton.clicked.connect(this,"close()");
			obj="Add cars on Map";
			break;

		default:
			break;
		}
        setWindowTitle(obj);
	}

	@SuppressWarnings("unused")
	private void buttonClicked() {
		
		if(object==0) {
			final int bb = Integer.parseInt(this.boxNum.currentText());
			((MainWindow)parent()).getMenuBarControl().setStepCarsNumber(bb);			
		}
		else{
			((MainWindow)parent()).getMenuBarControl().setAddedCars(true);
			
		}
	}
	
	@Override
	protected void closeEvent(QCloseEvent arg__1) {
		super.closeEvent(arg__1);
		if (object==1) {
			((MainWindow)parent()).getMenuBarControl().setAddedCars(false);			
		}
	}

}
